<link rel="stylesheet" href="css/bootstrap.css"/>
<?php
require_once('includes/common.php');
define('OFFSET',3); // Record Per Page
$url  = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
//pr($url); 
/************ Start For paging ***********/
$page = isset($_GET['page']) ? $_GET['page'] : 1;
//$limit = ($page * OFFSET )- OFFSET;
$limit = OFFSET *($page - 1);
/************ End For paging ***********/
 $selectCountQuery = "SELECT COUNT(*) AS `total` FROM `users`";

$selectCountResult = mysql_query($selectCountQuery) or die(mysql_error());
$ansCount = mysql_fetch_assoc($selectCountResult);
$selectQuery = "SELECT * FROM `users` LIMIT $limit,".OFFSET;
$selectResult = mysql_query($selectQuery) or die(mysql_error());

$totalPages = ceil($ansCount['total'] / OFFSET );

?>


<div>Total Users found:<?=$ansCount['total']?></div>
<table border="1" width="100%" class="table table-striped table-hover">
  <thead>
    <tr>
      <th>#ID</th>
      <th>
        Name
      </th>
      <th>Email</th>
      <th>Phone</th>
      <th>image</th>
      <th>Register Date</th>
      <th>Options</th>
    </tr>
  </thead>
<?php
while($ans  = mysql_fetch_assoc($selectResult))
{
  $uid = $ans['id'];
  ?>
    <tr>
      <td>

<a href="view_profile.php?id=<?=$ans['id']?>"><?=$uid?></a>
    </td>
      <td><?=$ans['name']?></td>
      <td><a href="mailto:<?=$ans['email']?>"><?=$ans['email']?></a></td>
      <td><?=$ans['phone']?></td>
      <td><img height="90" width="120" src="uploads/<?=$ans['image']?>" ></td>
       <td><?=date('d-M-Y l',strtotime($ans['register_date']))?></td>
      <td>
        <i class="icon-edit"></i>

        <a href="<?=$url?>?mode=delete&id=<?=$uid?>"]>
          <i class="icon-trash " onClick="return confirm('Are you sure to delete ?');"></i>
        </a>

      </td>
    </tr>
  <?php
}
?>
</table>
    <div class="pagination pagination-centered pagination-large">
		<ul>
			<li><a href="#">Prev</a></li>
<?php for($i=1 ; $i<= $totalPages ; $i++) {
$isActive = ($i == $page) ? 'active':'';
	
?>
			<li class="<?=$isActive?>">
<a href="<?=$url?>?page=<?=$i?>"><?=$i?></a></li>
<?}?>			

			<li>
<a href="<?=$url?>?page=<?=($page+1)?>">Next</a></li>
		</ul>
    </div>
